//
//  HomeViewCell.swift
//  WeiBoSwift
//
//  Created by 吴斌 on 2022/10/9.
//

import UIKit
import SwiftUI

private let edgeMargin : CGFloat = 15

class HomeViewCell: UITableViewCell {

    // MARK: - 空间属性
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var screenNameLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var sourceLabel: UILabel!
    @IBOutlet weak var contentLabel: UILabel!
    
    // MARK: - 约束属性
    @IBOutlet weak var contentLabelWCons: NSLayoutConstraint!
    
    // MARK: - 自定义属性
    var viewModel : StatusViewModel? {
        didSet {
            // 1.nil值校验
            guard let viewModel = viewModel else {
                return
            }
            
            // 2.设置头像
            iconView.kf.setImage(with: viewModel.profileURL, placeholder: UIImage(named: "logo"), options: nil, completionHandler: nil)
            
            // 3.昵称
            screenNameLabel.text = viewModel.status?.user?.screen_name
            
            // 4.设置时间的Label
            timeLabel.text = viewModel.createAtText
            
            // 5.设置来源
            sourceLabel.text = viewModel.sourceText
            
            // 6.设置昵称的文字颜色
            screenNameLabel.textColor = viewModel.vipImage == nil ? UIColor.black : UIColor.orange
            
            // 7.设置内容
            contentLabel.text = viewModel.status?.text

        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        // 设置微博正文的宽度约束
        contentLabelWCons.constant = UIScreen.main.bounds.width - 2 * edgeMargin
        
    }

}
